package com.domian.news.adapters;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ImageSpan;

import com.domian.news.utils.ParamName;

import java.util.List;

/**
 * Created by hhj on 2016-06-19.
 */
public class FMViewPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private List<Integer> drawable;
    private Context context;

    public FMViewPageAdapter(FragmentManager fm, Context context, List<Fragment> fragments) {
        super(fm);
        this.context = context;
        this.fragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        String tabTitle = fragments.get(position).getArguments().getString(ParamName.ARG_PARAM1);//Tab标题
       SpannableString spannableString = new SpannableString("   " + tabTitle);
       Drawable d = context.getDrawable(android.R.drawable.star_on);
        d.setBounds(0, 0, d.getIntrinsicWidth() / 2, d.getIntrinsicHeight() / 2);
        ImageSpan imageSpan = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);  //Tab标题的图标
        spannableString.setSpan(imageSpan, 0, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
}
